using System.Collections;
using System.Collections.Generic;
using MyFrame.Single;
using UnityEngine;
using UnityEngine.Events;

namespace MyFrame.Mono
{

    /// <summary>
    /// 提供给外部添加帧更新、协程事件的方法
    /// </summary>
    public class MonoMgr : Singleton<MonoMgr>
    {
        private MonoController monoController;

        public MonoMgr()
        {
            GameObject obj = new GameObject("MonoController");
            monoController = obj.AddComponent<MonoController>();
        }

        public void AddUpdateEvent(UnityAction action)
        {
            monoController.AddUpdateEvent(action);
        }

        public void RemoveUpdateEvent(UnityAction action)
        {
            monoController.RemoveUpdateEvent(action);
        }

        public Coroutine StartCoroutine(IEnumerator routine)
        {
            return monoController.StartCoroutine(routine);
        }

        public Coroutine StartCoroutine(string methodName, object value = null)
        {
            return monoController.StartCoroutine(methodName, value);
        }

        /// <summary>
        /// 方法名只能是controller中的方法
        /// </summary>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public Coroutine StartCoroutine(string methodName)
        {
            return monoController.StartCoroutine(methodName);
        }

        //停止协程
        public void StopCoroutine(Coroutine coroutine){
            monoController.StopCoroutine(coroutine);
        }
        public void StopAllCoroutines(){
            monoController.StopAllCoroutines();
        }
    }
}
